import Vue from "vue";
import VueRouter from "vue-router";
import Index from "../views/Index.vue";

Vue.use(VueRouter);

const routes = [
  //武振国路由
  {
    path: "/yd",
    name: "yd",
    meta: {
      // 隐藏头: true
      hideHeader: true,
      needLogin: true //需要登录    
    },
    component: () => import("../views/Yd.vue"),
  },
  // 李蒋龙路由
  {
    path: '/guonei',
    name: 'Guonei',
    component: () => import('../views/guonei.vue'),
  },
  {
    path: '/reg/xiugai',
    name: 'Xiugai',
    component: () => import('../views/xiugai.vue'),
  },
  {
    path: '/reg/denglu',
    name: 'Denglu',
    meta: {
      // 隐藏头: true
      hideHeader: true,
      hideFooter:true
    },
    component: () => import('../views/denglu.vue'),
  },
  //周游路由
  {
    path: '/borui',
    name: 'Borui',
    component: () => import('../views/Dynam.vue'),
  },
  //罗滢鑫路由
  {
    path: '/dzy',
    name: 'Dzy',
    meta: {
      // 隐藏头: true
      hideHeader: true,
    },
    component: () => import( '../views/Dzy.vue'),
    // children:[{
    //   path: 'dz',
    //   name: 'Dz',
    //   component: () => import('../views/Dz.vue'),
    // },
    
    // ]
  },
  {
    path: '/dzy/dz',
    name: 'Dz',
    meta: {
      // 隐藏头: true
      hideHeader: true,
    },
    component: () => import('../views/Dz.vue'),
  },
  // 向雪燕路由
  {
    path: '/yuding',
    name: 'Yuding',
    component: () => import('../views/yuding/YuDing.vue'),
  },
  {
    path: '/reg',
    name: 'Reg',
    meta: {
      // 隐藏头: true
      hideHeader: true,
      hideFooter:true
    },
    component: () => import('../views/Reg.vue'),
  },
  //罗先平路由
  //详情页路由
  {
    path: '/xiangqing',
    name: 'Xiangqing',
    component: () => import('../views/XiangQing.vue'),
  },
  {
    path: '/aboutus',
    name: 'Aboutus',
    // 从定向
    redirect: 'aboutus/dongtai',
    component: () => import('../views/AboutUs.vue'),
    children:[
      {
        path: 'dongtai',
        name: 'Dongtai',
        component: () => import('../views/DongTai.vue'),
      },
      {
        path: 'hezuo',
        name: 'Hezuo',
        component: () => import('../views/HeZuo.vue'),
      },
      {
        path: 'pinpai',
        name: 'Pinpai',
        component: () => import('../views/PinPai.vue'),
      },
      {
        path: 'wangdian',
        name: 'Wangdian',
        component: () => import('../views/WangDian.vue'),
      },
    ]
  },
  //陈阳路由
  {
    path: "/",
    // 路由重定向：当访问 / 是会立即跳转到 /home/index
    redirect: "/index/indexmain",
  },
  {
    path: "/order",
    // 路由重定向：当访问 / 是会立即跳转到 /home/index
    redirect: "/order/myorder",
  },

  {
    path: "/order",
    component: () => import("../views/Order.vue"),
    children: [
      {
        path: "myorder",
        meta:{
          needLogin: true //需要登录   
        },
        component: () => import("../views/order/MyOrder.vue"),
      },
      {
        path: "exchangeorder",
        component: () => import("../views/order/ExchangeOrder.vue"),
      },
      {
        path: "MyCollection",
        component: () => import("../views/order/MyCollection.vue"),
      },
      {
        path: "CommonTraveller",
        component: () => import("../views/order/CommonTraveller.vue"),
      },
      {
        path: "MyActivity",
        component: () => import("../views/order/MyActivity.vue"),
      },
      {
        path: "MyIntegral",
        component: () => import("../views/order/MyIntegral.vue"),
      },
      {
        path: "MyDiscountCoupon",
        component: () => import("../views/order/MyDiscountCoupon.vue"),
      },
      {
        path: "PersonalData",
        component: () => import("../views/order/PersonalData.vue"),
      },
      {
        path: "MyBeckoningCard",
        component: () => import("../views/order/MyBeckoningCard.vue"),
      },
    ],
  },
  {
    path: "/index",
    name: "首页",
    component: Index,
    children: [
      {
        path: "indexmain",
        component: () => import("../views/IndexMain.vue"),
      },
    ],
  },
];

const router = new VueRouter({
  mode: "history",
  routes,
});

router.beforeEach((to, from, next) => {
  let token = sessionStorage.getItem('phone')
  if (to.meta.needLogin) { // 判断该路由是否需要登录权限
    if (token) { //判断是否已登录
      next()
    }
    else {
      alert("请登录")
      next({path: '/reg/denglu'}) 
    }
  } else { 
  	next()
  }
})

 


export default router;
